
#region Imports

using System;
using System.Configuration.Provider;
using System.Data;
using System.Data.Common;

#endregion

namespace Justa.Data.Provider
{
    /// <summary>
    /// 
    /// </summary>
    /// 
    public abstract class DataAccessProvider : ProviderBase
    {
        /// <summary>
        /// 
        /// </summary>
        /// 
        private string databaseInstance;

        /// <summary>
        /// 
        /// </summary>
        /// 
        public DataAccessProvider()
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// 
        /// <param name="databaseInstance"></param>
        /// 
        public DataAccessProvider(string databaseInstance)
        {
            if (databaseInstance == null)
            {
                DataAccessExceptionHandler.Process(null, "Failed to construct provider.  Specified database instance name is null.");
            }

            this.databaseInstance = databaseInstance;
        }

        /// <summary>
        /// 
        /// </summary>
        /// 
        public string DatabaseInstance
        {
            get 
            { 
                return databaseInstance; 
            }
            set 
            { 
                databaseInstance = value; 
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// 
        public virtual void Init()
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// 
        /// <returns></returns>
        /// 
        public abstract DbConnection CreateConnection();

        /// <summary>
        /// 
        /// </summary>
        /// 
        /// <param name="command"></param>
        /// 
        /// <returns></returns>
        /// 
        public abstract DataSet ExecuteDataSet(DbCommand command);

        /// <summary>
        /// 
        /// </summary>
        /// 
        /// <param name="command"></param>
        /// 
        /// <returns></returns>
        /// 
        public abstract IDataReader ExecuteReader(DbCommand command);

        /// <summary>
        /// 
        /// </summary>
        /// 
        /// <param name="command"></param>
        /// <param name="transaction"></param>
        /// 
        /// <returns></returns>
        /// 
        public abstract IDataReader ExecuteReader(DbCommand command, DbTransaction transaction);

        /// <summary>
        /// 
        /// </summary>
        /// 
        /// <param name="command"></param>
        /// 
        public abstract void ExecuteNonQuery(DbCommand command);

        /// <summary>
        /// 
        /// </summary>
        /// 
        /// <param name="command"></param>
        /// <param name="transaction"></param>
        /// 
        public abstract void ExecuteNonQuery(DbCommand command, DbTransaction transaction);

        /// <summary>
        /// 
        /// </summary>
        /// 
        /// <param name="command"></param>
        /// 
        /// <returns></returns>
        /// 
        public abstract object ExecuteScalar(DbCommand command);

        /// <summary>
        /// 
        /// </summary>
        /// 
        /// <param name="query"></param>
        /// 
        /// <returns></returns>
        /// 
        public abstract DbCommand GetSqlStringCommand(string query);

        /// <summary>
        /// 
        /// </summary>
        /// 
        /// <param name="name"></param>
        /// 
        /// <returns></returns>
        /// 
        public abstract DbCommand GetStoredProcCommand(string name);

        /// <summary>
        /// 
        /// </summary>
        /// 
        /// <param name="name"></param>
        /// <param name="parameters"></param>
        /// 
        /// <returns></returns>
        /// 
        public abstract DbCommand GetStoredProcCommand(string name, params object[] parameters);

        /// <summary>
        /// 
        /// </summary>
        /// 
        /// <param name="command"></param>
        /// <param name="name"></param>
        /// <param name="dbType"></param>
        /// <param name="value"></param>
        /// 
        public abstract void AddInParameter(DbCommand command, string name, DbType dbType, object value);
    }
}
